package model.network.interceptor

import model.repository.UserRepository
import okhttp3.Interceptor
import okhttp3.Response


/**
 * @author wei kunJie
 * @date 2024/4/15 22:41:57
 */
class RequestInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {

        val token = UserRepository.token
        val originalRequest = chain.request()
        if (token == null) {
            return chain.proceed(originalRequest)
        }
        val authorised = originalRequest.newBuilder()
            .addHeader("token", token)
            .build()
        return chain.proceed(authorised)
    }
}